import { LoginResult, LoginUserInfo } from "./models";
import req, { RequsetOptons, ResponseData } from "/@/api/req";

export const Api = {
  login: "zyx-auth/oauth2/token",
  me: "zyx-system/api/v1/users/me",
};

export function handleLogin(data: { username: string; password: string }) {
  const formData = new FormData();
  formData.append("username", data.username);
  formData.append("password", data.password);
  formData.append("grant_type", "password");
  return req.post<LoginResult>(
    {
      url: Api.login,
      auth: {
        username: "zyx-admin",
        password: "123456",
      },
      data: formData,
    },
    {
      withToken: false,
    }
  );
}

export function getMeInfo(options?: RequsetOptons) {
  return req.commonGet<LoginUserInfo>(Api.me, {}, options);
}
